package com.example.springLearning.part7.config;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Service;

@Aspect
@Slf4j
@Service
public class AopConfig {

    @Around("execution(* com.example.springLearning.part7.service.ElectricService.pay())")
    public void recordPayPerformance(ProceedingJoinPoint joinPoint) throws Throwable {
        long start = System.currentTimeMillis();
        joinPoint.proceed();
        long end = System.currentTimeMillis();
        System.out.println("Pay method time cost (ms) : " + (end - start));
    }

    @Around("execution(* com.example.springLearning.part7.service.Fixed2ElectricService.pay())")
    public void recordPayPerformance2(ProceedingJoinPoint joinPoint) throws Throwable {
        long start = System.currentTimeMillis();
        joinPoint.proceed();
        long end = System.currentTimeMillis();
        System.out.println("Pay method time cost (ms) : " + (end - start));
    }

    @Around("execution(* com.example.springLearning.part7.service.Fixed3ElectricService.pay())")
    public void recordPayPerformance3(ProceedingJoinPoint joinPoint) throws Throwable {
        long start = System.currentTimeMillis();
        joinPoint.proceed();
        long end = System.currentTimeMillis();
        System.out.println("Pay method time cost (ms) : " + (end - start));
    }


}
